# -*- coding: utf-8 -*-
"""首页/公共导航元素页面对象。"""

from selenium.webdriver.common.by import By
from .base import BasePage


class HomePage(BasePage):
    # -------- 元素定位 --------
    LOGIN_LINK = (By.XPATH, "//a[contains(text(),'登录')]")
    REGISTER_LINK = (By.XPATH, "//a[contains(text(),'注册')]")
    # 登录成功后的欢迎文字区域（兼容 class 变化）
    USER_WELCOME = (By.XPATH, "//div[contains(@class,'login') and contains(@class,'btn')]")  # "欢迎您：XXX | 退出"

    # -------- 页面行为 --------
    def goto_login(self):
        """点击页面顶部“登录”跳转到登录页面"""
        self.click(self.LOGIN_LINK)

    def goto_register(self):
        """点击“注册”按钮跳转到注册页面"""
        self.click(self.REGISTER_LINK)

    def welcome_text(self) -> str:
        return self.text_of(self.USER_WELCOME)
